//
//  LLNavViewController.swift
//  新浪微博
//
//  Created by mac on 16/5/22.
//  Copyright © 2016年 mac.com. All rights reserved.
//

import UIKit

class LLNavViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate
         = self
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        var backTitle = "返回"
        if childViewControllers.count > 0 {
            if  childViewControllers.count == 1{
            
                //设置返回按钮的title = 顶级页面的title
                backTitle = childViewControllers.first?.title ?? "返回"
            
            }
            let back = UIBarButtonItem(imagename: "navigationbar_back_withtext", title: backTitle, target: self, action: Selector("popToFrontVC"))
        viewController.navigationItem.leftBarButtonItem = back
               }
        super.pushViewController(viewController, animated: true)
        
    }
   @objc private func popToFrontVC(){
    popViewControllerAnimated(true)
    }
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count > 1
    }
}
